<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@page import="com.simplefan.meta.MetaObject"%>
<%@page import="com.simplefan.meta.help.MetaObjectHelper"%>
<%@page import="com.simplefan.meta.engine.persister.entity.EntityPersister"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="org.springframework.context.support.ClassPathXmlApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="com.simplefan.meta.MetaClass"%>
<%@page import="com.simplefan.meta.QueryCriteria"%>
<%@page import="com.simplefan.meta.QueryExpressionUtil"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

MetaClass mc = MetaObjectHelper.getMetaClass("com.gxlu.ngrm.equipment.Vendor");
MetaObject mo = MetaObjectHelper.newInstance(mc);
try {
	ApplicationContext topApplicationContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
	EntityPersister persist = (EntityPersister)topApplicationContext.getBean("persister");
	QueryCriteria criterial = new QueryCriteria(mc);
	criterial.addExpression(QueryExpressionUtil.equals("NAMECN","TEST"));
	List<MetaObject> molist = persist.query(criterial).getList();
	
	if(molist==null || molist.isEmpty()){
		mo.setValue("NAMECN","TEST");
		mo.setValue("NAMEEN","TEST");
		mo.setPersistType(MetaObject.PERSIST_TYPE_ADD);
		persist.insert(mo);
	}else{
		mo = molist.get(0);
		mo.setValue("NAMEEN","wakaozhenkeyia");
		mo.setPersistType(MetaObject.PERSIST_TYPE_DELETE);
		persist.delete(mo);
	}
}
catch(Exception e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
}

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'test.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
 
  <body>
    
  </body>
</html>
